layui.use(['form', 'table','layuimini','element', 'tableSelect'], function () {
    var $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        layuimini = layui.layuimini,
        tableSelect = layui.tableSelect;

    /**
     * 初始化表单，要加上，不然刷新部分组件可能会不加载
     */
    form.render();

    var BoImgLog = {
        id: 'BoImgLogTable'
    };

    var column = [
        [
            {type: 'numbers'},
            {field: 'tableName', title: '业务表名', align: 'center'},
            {field: 'tableId', title: '业务表编号', align: 'center'},
            {field: 'imgName', title: '图片名', align: 'center'},
            {field: 'imgName', title: '图片', align: 'center',
                templet: function (object) {
                    var img = '<img src="' + object.imgPath + '/' + object.imgName +
                        '" lay-event="previewImg"' + ' style="cursor: pointer;max-width:100px; max-height:100px;"';
                    return img;
                }
            },
            {field: 'imgPath', title: '映射路径', align: 'center'},
            {field: 'imgSize', title: '图片大小', align: 'center',
                templet: function (object) {
                    var size = object.imgSize / 1024 / 1024;
                    return size.toFixed(3) + 'M';
                }
            },
            {field: 'createDate', title: '上传时间', minWidth: 120, align: 'center'}
        ]
    ];

    table.render({
        elem: '#' + BoImgLog.id,
        url: '/web/boImgLog/boContentImgList',
        cols: column,
        limits: [10, 15, 20, 25, 50, 100],
        limit: 15,
        page: true
    });

    //照片预览
    BoImgLog.previewImg = function(data) {

        var width = (window.screen.width - 400) + 'px';
        var height = (window.screen.height - 300) + 'px';

        var imgHtml = "<img src='" + data.imgPath + "/" + data.imgName + "' style='min-width:100px; min-height:100px;max-width:" + width + ";max-height:" + height + ";'/>";
        //捕获页
        var index = layer.open({
            type: 1,
            title: false, //不显示标题
            shadeClose: true,
            skin: 'previewImg-class', //透明
            area: ['auto', 'auto'],
            content: imgHtml //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
        });

    };

    //监听表格复选框选择
    // table.on('checkbox(currentTableFilter)', function (obj) {
    //     console.log(obj)
    // });

    //监听工具条
    table.on('tool(' + BoImgLog.id + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if(layEvent === 'previewImg'){
            BoImgLog.previewImg(data);
        }
    });

});